#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/9/6 16:55
# @Updatetime：16:55
# @Author：Test008
# @File：7-柱状图开发
# @Description：
from pyecharts.charts import Bar,Timeline
from pyecharts.options import *
from pyecharts.globals import ThemeType
from pyecharts import options
bar1 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [30, 20, 10, 15, 23, 33], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar2 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [33, 26, 30, 25, 43, 23], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar3 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [40, 10, 30, 45, 63, 13], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar4 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [34, 26, 18, 11, 43, 43], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar5 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [55, 34, 60, 30, 40, 80], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar6 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [78, 70, 120, 77, 88, 170], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
bar7 = (
    Bar()
        .add_xaxis(["深圳", "北京", "上海", "杭州", "成都", "广州"])
        .add_yaxis("GDP", [99, 140, 98, 250, 178, 230], label_opts=LabelOpts(position='right'))
        # x,y轴反转
        .reversal_axis()
    # .render()
)
# 创建时间线对象
timeline = (
    # 更换主题
    Timeline(init_opts=options.InitOpts(theme=ThemeType.CHALK))
        .add(bar1, "2017年GDP")
        .add(bar2, "2018年GDP")
        .add(bar3, "2019年GDP")
        .add(bar4, "2020年GDP")
        .add(bar5, "2021年GDP")
        .add(bar6, "2022年GDP")
        .add(bar7, "2023年GDP")
        # 设置自动播放
        .add_schema(
        play_interval=1000,  # 自动播放的时间，单位毫秒
        is_timeline_show=True,  # 是否自动播放时显示时间线
        is_auto_play=True,  # 是否自动播放
        is_loop_play=True  # 是否循环自动播放

    )
        # 绘制图表
        .render()
)
